﻿namespace Async_WhenAll;

class Program
{
    static async Task Main(string[] args)
    {
        var filesPath= Directory.GetFiles(@"E:\LiufengProjects\RiderProjects\PracticeFile");
        List<Task<int>> tasks = new List<Task<int>>();
        foreach (var filePath in filesPath)
        {
            Task<int> t = ReadCharsCount(filePath);
            tasks.Add(t);
        } 
        var result = await Task.WhenAll(tasks);
        Console.WriteLine(result.Sum().ToString());
    }

    static async Task<int> ReadCharsCount(string path)
    {
        var result = await File.ReadAllTextAsync(path);
        return result.Length;
    }
}